package com.controller.user;

import com.entity.Goods;
import com.proj.service.RecommendService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/** 主页以及商品页的推荐控制器 */
@RestController
@CrossOrigin
public class RecommendController {

  @Autowired RecommendService recommendService;

  /**
   * 按用户浏览历史推荐书籍（通过浏览历史，查看用户查看的书籍的种类前几名，然后推荐前几名种类的点击量最高的N本书籍）
   *
   * @param userId
   * @param categoryNum
   * @param goodsNum
   * @return 返回一个goods组
   */
  @GetMapping("home/getGoodsByCategoryIdsFromHistory")
  public List<Goods> getGoodsByCategoryIdsFromHistory(
      @RequestParam("userId") String userId,
      @RequestParam("categoryNum") int categoryNum,
      @RequestParam("goodsNum") int goodsNum) {
    return recommendService.getGoodsByCategoryIdsFromHistory(userId, categoryNum, goodsNum);
  }

  /**
   * 推荐点击量前N名的书籍
   *
   * @param goodsNum
   * @return
   */
  @GetMapping("home/getGoodsByVisit")
  public List<Goods> getGoodsByVisit(@RequestParam("goodsNum") int goodsNum) {
    return recommendService.getGoodsByVisit(goodsNum);
  }

  /**
   * 推荐收藏最多的N本书
   *
   * @param goodNum
   * @return
   */
  @GetMapping("home/getGoodsByCollection")
  public List<Goods> getGoodsByCollection(@RequestParam("goodNum") int goodNum) {
    return recommendService.getGoodsByCollection(goodNum);
  }

  /**
   * 浏览过该书籍的顾客也浏览过的书籍
   *
   * @param goodsNum
   * @param goodsId
   * @return
   */
  @GetMapping("home/getGoodsByGoodsFromHistory")
  public List<Goods> getGoodsByGoodsFromHistory(
      @RequestParam("goodsNum") int goodsNum, @RequestParam("goodsId") String goodsId) {
    return recommendService.getGoodsByGoodsFromHistory(goodsNum, goodsId);
  }

  /**
   * 购买过该书籍的顾客也购买过的书籍
   *
   * @param goodsNum
   * @param goodsId
   * @return
   */
  @GetMapping("home/getGoodsByGoodsFromOrder")
  public List<Goods> getGoodsByGoodsFromOrder(
      @RequestParam("goodsNum") int goodsNum, @RequestParam("goodsId") String goodsId) {
    return recommendService.getGoodsByGoodsFromOrder(goodsNum, goodsId);
  }

  /**
   * 基于用户过滤的推荐算法
   *
   * @param userId
   * @return
   */
  @GetMapping("home/recommendByUsers")
  public List<Goods> recommendByUsers(
      @RequestParam("userId") String userId, @RequestParam("goodNum") int goodNum) {
    return recommendService.recommendByUsers(userId, goodNum);
  }
}
